using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Recruiters_logo : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["rcuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (Session["rcactivate"].ToString() == "False")
        {
            btnUpload.Enabled = false;
            
            literalError.Text = "<img border=0 src='/icons/warning.gif'>You can not upload company logo, <br>because this account is not approved by management team.";
        }
        connectionString =
                     WebConfigurationManager.ConnectionStrings[
                       "RecruitVietnam"].ConnectionString;
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            string FolderToSave = Server.MapPath("") + "\\Logos\\";
            HttpPostedFile myFile = Request.Files[0];
            if (myFile != null && myFile.FileName != "")
            {
                myFile.SaveAs(FolderToSave + 
                Session.Contents["rcuserid"].ToString() 
                + System.IO.Path.GetExtension(myFile.FileName));
                literalError.Text = "File " 
                + myFile.FileName + " succesfully saved.<br>" ;

                RecruitVietnam recruitVietnam = new RecruitVietnam();
                recruitVietnam.ConnectionString = connectionString;
                if (!recruitVietnam.UploadLogo(Session.Contents["rcuserid"].ToString()))
                    literalError.Text = recruitVietnam.ErrorMessage;
            }
            else
                literalError.Text = "No files sent. Script is OK!";
        }
        catch(Exception ex)
        {
            literalError.Text = ex.Message;
        }
    }
}
